<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<ui:composition template="/layout/template.xhtml">

	<ui:define name="title">
		<h:outputText value="#{appMsg['title.list.levels']}" />
	</ui:define>

	<ui:define name="content">

		<h:panelGrid id="listPanel">
			<h:form id="form" style="width : 30em">
				<p:dataTable id="dataTable" value="#{levelsHome.levels}" var="p">
					<f:facet name="header">
						<p:commandButton value="cancel edit" update=":editPanel :listPanel"
							actionListener="#{levelsView.cancelEditLevel()}" disabled="#{!levelsView.editMode}" />
						<p:commandButton value="new" update=":editPanel :listPanel"
							actionListener="#{levelsView.editNewLevel()}" disabled="#{levelsView.editMode}" />
					</f:facet>
					<p:column>
						<p:commandButton value="edit" update=":editPanel :listPanel"
							actionListener="#{levelsView.setEditLevelById(p.id)}" disabled="#{levelsView.editMode}" />
					</p:column>
					<p:column sortBy="#{p.name}">
						<f:facet name="header">
							<h:outputText value="#{appMsg['level.name']}" />
						</f:facet>
						<h:outputText value="#{p.name}" />
					</p:column>
				</p:dataTable>
			</h:form>
		</h:panelGrid>

		<h:panelGrid columns="2">
			<p:panel id="editPanel" styleClass="peel-no-border">
				<p:panel rendered="#{levelsView.editMode}"
					header="#{levelHome.level.id ne null ? appMsg['title.update.level'] : appMsg['title.create.level']}">
					<h:form id="formLevel">
						<h:panelGrid>
							<h:panelGrid columns="2">
								<h:outputLabel value="#{appMsg['level.name']}" />
								<p:inputText id="lastname" label="#{appMsg['level.name']}" value="#{levelHome.level.name}"
									required="true">
								</p:inputText>
							</h:panelGrid>
							<h:panelGroup>
								<p:commandButton id="merge" actionListener="#{levelsView.updateLevel()}"
									update=":editPanel :listPanel"
									value="#{levelHome.level.id ne null ? appMsg['update'] : appMsg['create']}" />
								<p:spacer width="5px" />
								
								<p:commandButton id="delete" value="#{appMsg['delete']}" rendered="#{levelHome.level.id ne null}"
									onclick="confirmDialog.show()" type="button"/>
									
								<p:spacer width="5px" />
								<p:commandButton id="cancel" process="@this" value="#{appMsg['cancel']}"
									update=":editPanel :listPanel" actionListener="#{levelsView.cancelEditLevel()}" />
							</h:panelGroup>
						</h:panelGrid> 
					</h:form>
				</p:panel>
			</p:panel>
		</h:panelGrid>
	</ui:define>
	
	<ui:define name="bottomcontent">
		<p:confirmDialog message="'#{appMsg['confirm.delete']} #{appMsg['level']}" header="Confirmer votre choix"
			severity="alert" widgetVar="confirmDialog" id="cd">
			<h:form id="cdform">
				<p:commandButton value="Oui" actionListener="#{levelsView.deleteLevel()}" oncomplete="confirmDialog.hide();"
					update=":editPanel :listPanel" />
				<p:commandButton value="Non" onclick="confirmDialog.hide();" type="button" />
			</h:form>
		</p:confirmDialog>
	</ui:define>
	
</ui:composition>
</html>
